<?php
namespace App\Providers\VersionTraits;

use App\Models\Shop\WxShopGoods;
use Dcat\Admin\Models\Menu;
use Dcat\Admin\Models\Permission;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

trait _1_0_10_trait{
    /** v1.0.1的数据表升级
     * @return bool
     */
    function _v1_0_1()
    {

        if(Schema::hasColumn('wx_user', 'external_id')){
            Schema::table('wx_user', function (Blueprint $table) {
                $table->dropColumn('external_id');
            });
        }

        if(Schema::hasColumn('wx_posts', 'external_id')){
            Schema::table('wx_posts', function (Blueprint $table) {
                $table->dropColumn('external_id');
            });
        }

        if(Schema::hasColumn('wx_shop_goods', 'external_id')){
            Schema::table('wx_shop_goods', function (Blueprint $table) {
                $table->dropColumn('external_id');
            });
        }

        if(Schema::hasColumn('wx_comment', 'external_id')){
            Schema::table('wx_comment', function (Blueprint $table) {
                $table->dropColumn('external_id');
            });
        }

        // 微信小商店端的微信openid
        if(!Schema::hasColumn('wx_user', 'weixin_shop_openid')){
            Schema::table('wx_user', function (Blueprint $table) {
                $table->string('weixin_shop_openid', 255)->nullable()->after('weixin_openid')->comment('微信小商店端微信openid');
                $table->unique('weixin_shop_openid', 'index_14');
            });
        }

        // 微信小商店端的微信openid
        if(!Schema::hasColumn('wx_user', 'weixin_web_openid')){
            Schema::table('wx_user', function (Blueprint $table) {
                $table->string('weixin_web_openid', 255)->nullable()->after('weixin_openid')->comment('网站端微信openid');
                $table->unique('weixin_web_openid', 'index_13');
            });
        }

        // 公众号端的openid
        if(!Schema::hasColumn('wx_user', 'weixin_mp_openid')){
            Schema::table('wx_user', function (Blueprint $table) {
                $table->string('weixin_mp_openid', 255)->nullable()->after('weixin_openid')->comment('公众号端微信openid');
                $table->unique('weixin_mp_openid', 'index_12');
            });
        }

        // app端的微信openid
        if(!Schema::hasColumn('wx_user', 'weixin_app_openid')){
            Schema::table('wx_user', function (Blueprint $table) {
                $table->string('weixin_app_openid', 255)->nullable()->after('weixin_openid')->comment('app端微信openid');
                $table->unique('weixin_app_openid', 'index_11');
            });
        }


        if(!Schema::hasColumn('wx_user', 'weixin_unionid')){
            Schema::table('wx_user', function (Blueprint $table) {
                $table->string('weixin_unionid', 255)->nullable()->after('weixin_openid')->comment('微信unionid');
                $table->unique('weixin_unionid', 'index_10');
            });
        }

        if(!Schema::hasColumn('wx_shop_order_goods', 'recharge')){
            Schema::table('wx_shop_order_goods', function (Blueprint $table) {
                $table->float('recharge')->nullable()->after('price')->comment('实付');
            });
        }

        if(!Schema::hasTable('wx_sync_relation')){
            Schema::create('wx_sync_relation', function (Blueprint $table) {
                $table->id();
                $table->string('domain', 255)->comment('域名');
                $table->string('type', 20)->comment('类型');
                $table->string('inner_id', 50)->comment('内部id');
                $table->string('external_id', 50)->comment('外部id');
                $table->string('status', 10)->comment('状态(1,2,3)');
                $table->timestamps();
                $table->index(['domain','type'], 'index_0');
                $table->index('inner_id', 'index_1');
                $table->index('external_id', 'index_2');
            });
        }

        if(!Schema::hasTable('wx_refund')){
            Schema::create('wx_refund', function (Blueprint $table) {
                $table->id();
                $table->integer('user_id')->comment('退款用户');
                $table->integer('order_good_id')->comment('订单商品id');
                $table->integer('order_id')->comment('订单id');
                $table->integer('goods_id')->comment('商品id');
                $table->integer('product_id')->comment('规格id');
                $table->decimal('amount', $precision = 10, $scale = 2)->comment('退回金额');
                $table->timestamps();
                $table->index('user_id', 'index_0');
                $table->unique('order_good_id');
            });
        }


        if(!Menu::where('uri', '/shop/refund')->exists()){
            $admin_menu = new Menu();
            $admin_menu->parent_id = 36;
            $admin_menu->order =  35;
            $admin_menu->title = '退款';
            $admin_menu->uri = '/shop/refund';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

        if(!Permission::where('slug', 'shop_refund')->exists()){
            $permission = new Permission();
            $permission->name = '商城管理-退款';
            $permission->slug = 'shop_refund';
            $permission->http_method = '';
            $permission->http_path = '/shop/refund*';
            $permission->order = 26;
            $permission->parent_id = 0;
            $permission->save();
        }

        if(!Menu::where('uri', '/settings/pay')->exists()){
            $admin_menu = new Menu();
            $admin_menu->parent_id = 8;
            $admin_menu->order =  6;
            $admin_menu->title = '支付';
            $admin_menu->uri = '/settings/pay';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

        if(!Permission::where('slug', 'settings_pay')->exists()){
            $permission = new Permission();
            $permission->name = '全局配置-支付';
            $permission->slug = 'settings_pay';
            $permission->http_method = '';
            $permission->http_path = '/settings/pay*,/settings/action/pay*';
            $permission->order = 36;
            $permission->parent_id = 0;
            $permission->save();
        }

        if(Menu::where([['id', '=', 60],['title', '=', '小程序端']])->exists()){
            Menu::where('id',60)->update(['title'=>'移动端']);
        }

        if(!Menu::where('uri', '/settings/app')->exists()){
            $admin_menu = new Menu();
            $admin_menu->parent_id =60;
            $admin_menu->order =  6;
            $admin_menu->title = 'App';
            $admin_menu->uri = '/settings/app';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }


        // 话题pc端背景
        if(!Schema::hasColumn('wx_tags', 'pc_background_maps')){
            Schema::table('wx_tags', function (Blueprint $table) {
                $table->string('pc_background_maps', 255)->after('tags_name')->nullable()->comment('pc端背景');
            });
        }
        // 话题移动端背景
        if(!Schema::hasColumn('wx_tags', 'background_maps')){
            Schema::table('wx_tags', function (Blueprint $table) {
                $table->string('background_maps', 255)->after('tags_name')->nullable()->comment('移动端背景');
            });
        }
        // 话题头像
        if(!Schema::hasColumn('wx_tags', 'head_portrait')){
            Schema::table('wx_tags', function (Blueprint $table) {
                $table->string('head_portrait', 255)->after('tags_name')->nullable()->comment('头像');
            });
        }
        // 话题描述
        if(!Schema::hasColumn('wx_tags', 'tag_introduce')){
            Schema::table('wx_tags', function (Blueprint $table) {
                $table->string('tag_introduce', 255)->after('tags_name')->nullable()->comment('描述');
            });
        }


        if(!Schema::hasColumn('wx_posts', 'is_blur')){
            Schema::table('wx_posts', function (Blueprint $table) {
                $table->String('is_blur')->default(0)->after('is_reward')->comment('图片高斯模糊');
            });
        }
        if(Schema::hasColumn('wx_user', 'is_member') && Schema::getColumnType('wx_user', 'is_member') != 'string'){
            Schema::table('wx_user', function (Blueprint $table) {
                $table->dropColumn('is_member');

            });
        }

        if(!Schema::hasColumn('wx_user', 'is_member')){
            Schema::table('wx_user', function (Blueprint $table) {
                $table->string('is_member', 255)->after('is_official')->nullable()->default('')->comment('是否会员');
            });
        }
    }

    function _v1_0_2(){

        if(!Schema::hasTable('wx_user_meta_num')){
            Schema::create('wx_user_meta_num', function (Blueprint $table) {
                $table->id();
                $table->bigInteger('user_id')->comment('user_id');
                $table->string('meta_key', 255)->comment('meta_key');
                $table->bigInteger('meta_value')->comment('meta_value');
                $table->index(['user_id','meta_key'], 'index_0');
            });
        }
        if(!Schema::hasTable('wx_user_meta_str')){
            Schema::create('wx_user_meta_str', function (Blueprint $table) {
                $table->id();
                $table->bigInteger('user_id')->comment('user_id');
                $table->string('meta_key', 255)->comment('meta_key');
                $table->longText('meta_value')->comment('meta_value');
                $table->index(['user_id','meta_key'], 'index_0');
            });
        }
        if(!Schema::hasTable('wx_posts_meta_num')){
            Schema::create('wx_posts_meta_num', function (Blueprint $table) {
                $table->id();
                $table->bigInteger('post_id')->comment('post_id');
                $table->string('meta_key', 255)->comment('meta_key');
                $table->bigInteger('meta_value')->comment('meta_value');
                $table->index(['post_id','meta_key'], 'index_0');
            });
        }
        if(!Schema::hasTable('wx_posts_meta_str')){
            Schema::create('wx_posts_meta_str', function (Blueprint $table) {
                $table->id();
                $table->bigInteger('post_id')->comment('post_id');
                $table->string('meta_key', 255)->comment('meta_key');
                $table->longText('meta_value')->comment('meta_value');
                $table->index(['post_id','meta_key'], 'index_0');
            });
        }

        if(!Schema::hasTable('wx_comment_meta_num')){
            Schema::create('wx_comment_meta_num', function (Blueprint $table) {
                $table->id();
                $table->bigInteger('comment_id')->comment('comment_id');
                $table->string('meta_key', 255)->comment('meta_key');
                $table->bigInteger('meta_value')->comment('meta_value');
                $table->index(['comment_id','meta_key'], 'index_0');
            });
        }
        if(!Schema::hasTable('wx_comment_meta_str')){
            Schema::create('wx_comment_meta_str', function (Blueprint $table) {
                $table->id();
                $table->bigInteger('comment_id')->comment('comment_id');
                $table->string('meta_key', 255)->comment('meta_key');
                $table->longText('meta_value')->comment('meta_value');
                $table->index(['comment_id','meta_key'], 'index_0');
            });
        }

        if(!Schema::hasTable('wx_circle_meta_num')){
            Schema::create('wx_circle_meta_num', function (Blueprint $table) {
                $table->id();
                $table->bigInteger('circle_id')->comment('circle_id');
                $table->string('meta_key', 255)->comment('meta_key');
                $table->bigInteger('meta_value')->comment('meta_value');
                $table->index(['circle_id','meta_key'], 'index_0');
            });
        }

        if(!Schema::hasTable('wx_circle_meta_str')){
            Schema::create('wx_circle_meta_str', function (Blueprint $table) {
                $table->id();
                $table->bigInteger('circle_id')->comment('circle_id');
                $table->string('meta_key', 255)->comment('meta_key');
                $table->longText('meta_value')->comment('meta_value');
                $table->index(['circle_id','meta_key'], 'index_0');
            });
        }

        if(!Schema::hasTable('wx_tag_meta_num')){
            Schema::create('wx_tag_meta_num', function (Blueprint $table) {
                $table->id();
                $table->bigInteger('tag_id')->comment('tag_id');
                $table->string('meta_key', 255)->comment('meta_key');
                $table->bigInteger('meta_value')->comment('meta_value');
                $table->index(['tag_id','meta_key'], 'index_0');
            });
        }

        if(!Schema::hasTable('wx_tag_meta_str')){
            Schema::create('wx_tag_meta_str', function (Blueprint $table) {
                $table->id();
                $table->bigInteger('tag_id')->comment('tag_id');
                $table->string('meta_key', 255)->comment('meta_key');
                $table->longText('meta_value')->comment('meta_value');
                $table->index(['tag_id','meta_key'], 'index_0');
            });
        }

        if(!Schema::hasTable('wx_shop_good_meta_num')){
            Schema::create('wx_shop_good_meta_num', function (Blueprint $table) {
                $table->id();
                $table->unsignedBigInteger('good_id')->comment('good_id');
                $table->string('meta_key', 255)->comment('meta_key');
                $table->unsignedBigInteger('meta_value')->comment('meta_value');
                $table->index(['good_id','meta_key'], 'index_0');
            });
        }

        if(!Schema::hasTable('wx_shop_good_meta_str')){
            Schema::create('wx_shop_good_meta_str', function (Blueprint $table) {
                $table->id();
                $table->unsignedBigInteger('good_id')->comment('good_id');
                $table->string('meta_key', 255)->comment('meta_key');
                $table->longText('meta_value')->comment('meta_value');
                $table->index(['good_id','meta_key'], 'index_0');
            });
        }

        if(!Schema::hasTable('wx_wallpapers')){
            Schema::create('wx_wallpapers', function (Blueprint $table) {
                $table->id();
                $table->unsignedBigInteger('subject_id')->comment('主题id');
                $table->longText('imgs')->default('')->comment('图片');
                $table->string('title')->default('')->comment('标题');
                $table->unsignedBigInteger('user_id')->comment('作者id');
                $table->timestamps();
                $table->softDeletes();
                $table->index('user_id', 'index_0');
            });
        }

        if(!Schema::hasTable('wx_wallpapers_subject')){
            Schema::create('wx_wallpapers_subject', function (Blueprint $table) {
                $table->id();
                $table->string('name')->default('')->comment('名称');
                $table->string('img')->default('')->comment('图片');
                $table->string('desc')->default('')->comment('描述');
                $table->tinyInteger('status')->default(1)->comment('状态');
                $table->softDeletes();
                $table->timestamps();
            });
        }

        if(!Menu::where([ ['parent_id', '=', 0], ['title', '=', '图集管理'] ])->exists()){
            $admin_menu = new Menu();
            $admin_menu->icon = 'fa-picture-o';
            $admin_menu->parent_id = 0;
            $admin_menu->order =  43;
            $admin_menu->title = '图集管理';
//                $admin_menu->uri = '';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
            $parent_id = $admin_menu->id;


            if(!Menu::where('uri', '/wallpaper/subject')->exists()){
                $wallpaper_menu = new Menu();
                $wallpaper_menu->parent_id = $parent_id;
                $wallpaper_menu->order =  44;
                $wallpaper_menu->title = '主题';
                $wallpaper_menu->uri = '/wallpaper/subject';
                $wallpaper_menu->extension = '';
                $wallpaper_menu->show = 1;
                $wallpaper_menu->save();
            }

            if(!Menu::where('uri', '/wallpaper')->exists()){
                $wallpaper_menu = new Menu();
                $wallpaper_menu->parent_id = $parent_id;
                $wallpaper_menu->order =  45;
                $wallpaper_menu->title = '图集';
                $wallpaper_menu->uri = '/wallpaper/item';
                $wallpaper_menu->extension = '';
                $wallpaper_menu->show = 1;
                $wallpaper_menu->save();
            }
        }

    }

    private function _v1_0_3(){

        // 微信小商店端的微信openid
        if(!Schema::hasColumn('wx_user', 'email')){
            Schema::table('wx_user', function (Blueprint $table) {
                $table->string('email', 255)->after('weixin_shop_openid')->comment('邮箱');
                $table->index('email', 'index_15');
            });
        }
        if(!Schema::hasColumn('wx_user', 'phone')){
            Schema::table('wx_user', function (Blueprint $table) {
                $table->string('phone', 255)->after('weixin_shop_openid')->comment('手机');
                $table->index('phone', 'index_16');
            });
        }

        if(!Menu::where('uri', '/qa/question')->exists()){
            $admin_menu = new Menu();
            $admin_menu->parent_id = 22;
            $admin_menu->order =  45;
            $admin_menu->title = '帮助';
            $admin_menu->uri = '/qa/question';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

        if(!Schema::hasTable('wx_questions')){
            Schema::create('wx_questions', function (Blueprint $table) {
                $table->id();
                $table->string('title')->default('')->comment('标题');
                $table->longText('content')->nullable()->comment('内容');
                $table->integer('type')->default(0)->comment('类别');
                $table->timestamps();
            });
        }

        if(!Schema::hasColumn('wx_feedback', 'is_solve')){
            Schema::table('wx_feedback', function (Blueprint $table) {
                $table->tinyInteger('is_solve')->default(0)->after('feedback_reply')->comment('是否解决（0，待处理）');
            });
        }

        if(!Schema::hasColumn('wx_feedback', 'feedback_contact')){
            Schema::table('wx_feedback', function (Blueprint $table) {
                $table->string('feedback_contact', 255)->after('feedback_reply')->comment('联系');
            });
        }

        if(!Schema::hasColumn('wx_feedback', 'feedback_imgs')){
            Schema::table('wx_feedback', function (Blueprint $table) {
                $table->string('feedback_imgs', 255)->after('feedback_reply')->comment('图片');
            });
        }

        if(!Schema::hasTable('wx_posts_vote')){
            Schema::create('wx_posts_vote', function (Blueprint $table) {
                $table->id();
                $table->bigInteger('post_id')->comment('内容id');

                $table->string('option1')->default('')->comment('选项1');
                $table->bigInteger('num1')->default(0)->comment('选项1投票数');

                $table->string('option2')->default('')->comment('选项2');
                $table->bigInteger('num2')->default(0)->comment('选项2投票数');

                $table->string('option3')->nullable()->comment('选项3');
                $table->bigInteger('num3')->default(0)->comment('选项3投票数');

                $table->string('option4')->nullable()->comment('选项4');
                $table->bigInteger('num4')->default(0)->comment('选项4投票数');

                $table->string('option5')->nullable()->comment('选项5');
                $table->bigInteger('num5')->default(0)->comment('选项5投票数');

                $table->softDeletes();
                $table->timestamps();
                $table->index('post_id', 'index_0');
            });
        }

        if(!Schema::hasTable('wx_user_vote')){
            Schema::create('wx_user_vote', function (Blueprint $table) {
                $table->id();
                $table->bigInteger('user_id')->comment('用户id');
                $table->bigInteger('vote_id')->comment('投票id');
                $table->tinyInteger('vote_option')->comment('投票选项');
                $table->softDeletes();
                $table->timestamps();
                $table->index(['user_id', 'vote_id'], 'index_0');
            });
        }


        if(!Menu::where('uri', '/vote')->exists()){
            $admin_menu = new Menu();
            $admin_menu->parent_id = 14;
            $admin_menu->order =  29;
            $admin_menu->title = '投票';
            $admin_menu->uri = '/vote';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

        if(!Menu::where('uri', '/uservote')->exists() && !Menu::where('uri', '/user/vote')->exists()){
            $admin_menu = new Menu();
            $admin_menu->parent_id = 22;
            $admin_menu->order =  59;
            $admin_menu->title = '投票';
            $admin_menu->uri = '/uservote';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }
    }


    private function _v1_0_4(){
        if(!Schema::hasTable('wx_user_coin_record')){
            Schema::create('wx_user_coin_record', function (Blueprint $table) {
                $table->id();
                $table->bigInteger('user_id')->comment('用户id');
                $table->bigInteger('incre')->comment('增量');
                $table->string('tip')->comment('说明');
                $table->softDeletes();
                $table->timestamps();
                $table->index('user_id', 'index_0');
            });
        }

        if(!Schema::hasTable('wx_user_luck_draw_record')){
            Schema::create('wx_user_luck_draw_record', function (Blueprint $table) {
                $table->id();
                $table->bigInteger('user_id')->comment('用户id');
                $table->integer('pay')->comment('付费方式');
                $table->integer('type')->comment('奖品类型');
                $table->bigInteger('num')->comment('奖品数量');
                $table->string('tip')->comment('说明');
                $table->softDeletes();
                $table->timestamps();
                $table->index('user_id', 'index_0');
            });
        }


        if(Menu::where('uri', 'user')->exists()){
            Menu::where('uri', 'user')->update(['uri'=> '/users']);
        }

        if(Menu::where('uri', '/uservote')->exists()){
            Menu::where('uri', '/uservote')->update(['uri'=> '/user/vote']);
        }

        if(!Menu::where('uri', '/user/luckdraw')->exists()){
            $admin_menu = new Menu();
            $admin_menu->parent_id = 22;
            $admin_menu->order =  61;
            $admin_menu->title = '抽奖';
            $admin_menu->uri = '/user/luckdraw';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

        if(!Schema::hasTable('wx_user_financial_record')){
            Schema::create('wx_user_financial_record', function (Blueprint $table) {
                $table->id();
                $table->bigInteger('user_id')->comment('用户id');
                $table->bigInteger('num')->comment('增量');
                $table->integer('type')->comment('类型');
                $table->bigInteger('object')->nullable()->comment('对象');
                $table->string('tip')->comment('说明');
                $table->softDeletes();
                $table->timestamps();
                $table->index('user_id', 'index_0');
                $table->index('type', 'index_1');
            });
        }

        if(!Schema::hasColumn('wx_shop_classify', 'bg_img')){
            Schema::table('wx_shop_classify', function (Blueprint $table) {
                $table->string('bg_img', 255)->after('pic')->nullable()->comment('背景图');
            });
        }

    }

    private function _v1_0_5(){
        if(!Schema::hasColumn('wx_posts', 'last_reply_at')){
            Schema::table('wx_posts', function (Blueprint $table) {
                $table->timestamp('last_reply_at')->default('2022-12-09 14:18:00')->after('is_blur')->comment('最后回复时间');
            });
        }
        if(!Schema::hasColumn('wx_posts', 'weight')){
            Schema::table('wx_posts', function (Blueprint $table) {
                $table->timestamp('weight')->default('2022-12-09 14:18:00')->after('is_blur')->comment('计算热度');
            });
        }
    }

    private function _v1_0_6(){
        if(Menu::where('uri', 'update/index')->exists()){
            Menu::where('uri', 'update/index')->delete();
        }

        if(!Schema::hasTable('wx_user_sign_record')){
            Schema::create('wx_user_sign_record', function (Blueprint $table) {
                $table->id();
                $table->bigInteger('user_id')->comment('用户id');
                $table->softDeletes();
                $table->timestamps();
                $table->index('user_id', 'index_0');
            });
        }

        if(!Menu::where('uri', '/user/sign')->exists()){
            $admin_menu = new Menu();
            $admin_menu->parent_id = 22;
            $admin_menu->order =  62;
            $admin_menu->title = '签到';
            $admin_menu->uri = '/user/sign';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

        if(!Schema::hasTable('wx_tasks')){
            Schema::create('wx_tasks', function (Blueprint $table) {
                $table->id();
                $table->string('name')->comment('名字');
                $table->integer('type')->comment('类型');
                $table->integer('condition_type_0')->default(0)->comment('条件类型');
                $table->integer('condition_type_1')->default(0)->comment('条件类型');
                $table->bigInteger('condition_num')->comment('条件数量');
                $table->integer('reward_type')->comment('奖励类型');
                $table->bigInteger('reward_num')->comment('奖励数量');
                $table->integer('target_type')->nullable()->comment('跳转类型');
                $table->string('target_id', 255)->nullable()->comment('跳转id');
                $table->softDeletes();
                $table->timestamps();
            });
        }

        if(!Schema::hasTable('wx_user_task')){
            Schema::create('wx_user_task', function (Blueprint $table) {
                $table->id();
                $table->bigInteger('user_id')->comment('用户id');
                $table->bigInteger('task_id')->comment('任务id');
                $table->softDeletes();
                $table->timestamps();
            });
        }

        if(!Menu::where([ ['parent_id', '=', 0], ['title', '=', '任务系统'] ])->exists()){
            $admin_menu = new Menu();
            $admin_menu->icon = 'fa-check-square-o';
            $admin_menu->parent_id = 0;
            $admin_menu->order =  44;
            $admin_menu->title = '任务系统';
//                $admin_menu->uri = '';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
            $parent_id = $admin_menu->id;

            if(!Menu::where('uri', '/tasks/0')->exists()){
                $admin_menu = new Menu();
                $admin_menu->parent_id = $parent_id;
                $admin_menu->order =  63;
                $admin_menu->title = '每日';
                $admin_menu->uri = '/tasks/day';
                $admin_menu->extension = '';
                $admin_menu->show = 1;
                $admin_menu->save();
            }

            if(!Menu::where('uri', '/tasks/1')->exists()){
                $admin_menu = new Menu();
                $admin_menu->parent_id = $parent_id;
                $admin_menu->order =  63;
                $admin_menu->title = '成长';
                $admin_menu->uri = '/tasks/once';
                $admin_menu->extension = '';
                $admin_menu->show = 1;
                $admin_menu->save();
            }

            if(!Menu::where('uri', '/user/task')->exists()){
                $admin_menu = new Menu();
                $admin_menu->parent_id = $parent_id;
                $admin_menu->order =  64;
                $admin_menu->title = '用户';
                $admin_menu->uri = '/user/task';
                $admin_menu->extension = '';
                $admin_menu->show = 1;
                $admin_menu->save();
            }

        }

    }

    private function _v1_0_7(){
        if(!Menu::where('uri', '/settings/safe')->exists()){
            $admin_menu = new Menu();
            $admin_menu->parent_id = 8;
            $admin_menu->order =  7;
            $admin_menu->title = '安全';
            $admin_menu->uri = '/settings/safe';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

        if(!Schema::hasColumn('wx_shop_goods', 'type')){
            Schema::table('wx_shop_goods', function (Blueprint $table) {
                $table->tinyInteger('type')->default(0)->after('id')->comment('商品类型');
            });
            WxShopGoods::where('url', '<>', '')->update(['type'=>1]);
        }

        if(!Schema::hasColumn('wx_shop_goods', 'paid_content')){
            Schema::table('wx_shop_goods', function (Blueprint $table) {
                $table->text('paid_content')->nullable()->after('content')->comment('付费内容');
            });
        }

        if(!Menu::where('uri', '/settings/api')->exists()){
            $admin_menu = new Menu();
            $admin_menu->parent_id = 8;
            $admin_menu->order =  8;
            $admin_menu->title = 'API';
            $admin_menu->uri = '/settings/api';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

        if(!Schema::hasColumn('wx_shop_order_goods', 'paid_content')){
            Schema::table('wx_shop_order_goods', function (Blueprint $table) {
                $table->mediumText('paid_content')->nullable()->after('name')->comment('虚拟发货信息');
            });
        }

        if(!Schema::hasColumn('wx_shop_order', 'has_virtual')){
            Schema::table('wx_shop_order', function (Blueprint $table) {
                $table->tinyInteger('has_virtual')->default(0)->after('express_no')->comment('是否存在虚拟商品');
            });
        }

        if(!Menu::where('uri', '/settings/icons')->exists()){
            $admin_menu = new Menu();
            $admin_menu->parent_id = 8;
            $admin_menu->order =  9;
            $admin_menu->title = '图标';
            $admin_menu->uri = '/settings/icons';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

        if(!Schema::hasTable('wx_icons')){
            Schema::create('wx_icons', function (Blueprint $table) {
                $table->id();
                $table->string('name')->comment('名字');
                $table->string('icon')->nullable()->comment('icon');
                $table->string('desc')->nullable()->comment('描述');
                $table->integer('type')->comment('类型');
                $table->string('target_id', 255)->nullable()->default('')->comment('跳转id');
                $table->softDeletes();
                $table->timestamps();
            });
        }

        if(!Schema::hasColumn('wx_comment', 'is_sticky')){
            Schema::table('wx_comment', function (Blueprint $table) {
                $table->tinyInteger('is_sticky')->default(0)->after('comment_id')->comment('是否置顶');
            });
        }

    }

    private function _v1_0_8(){
        if(!Schema::hasTable('wx_user_report')){
            Schema::create('wx_user_report', function (Blueprint $table) {
                $table->id();
                $table->tinyInteger('type')->comment('类型');
                $table->bigInteger('user_id')->comment('用户id');
                $table->bigInteger('object_id')->comment('对象id');
                $table->tinyInteger('report_type')->comment('举报类型');
                $table->string('report_message')->comment('举报理由');
                $table->string('report_imgs')->comment('举报图片');
                $table->string('contact')->comment('联系方式');
                $table->softDeletes();
                $table->timestamps();
                $table->index(['type', 'object_id','user_id'], 'index_0');
            });
        }

        if(!Menu::where('uri', '/user/report')->exists()){
            $admin_menu = new Menu();
            $admin_menu->parent_id = 22;
            $admin_menu->order =  63;
            $admin_menu->title = '举报';
            $admin_menu->uri = '/user/report';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

    }

    private function _v1_0_9(){
        if(!Schema::hasTable('wx_activity')){
            Schema::create('wx_activity', function (Blueprint $table) {
                $table->id();
                $table->string('title')->comment('标题');
                $table->string('intro')->nullable()->comment('介绍');
                $table->string('pic')->nullable()->comment('图片');
                $table->tinyInteger('target_type')->comment('跳转类型');
                $table->string('target_id')->nullable()->comment('跳转id');
                $table->tinyInteger('status')->comment('状态');
                $table->softDeletes();
                $table->timestamps();
            });
        }

        if(!Menu::where('uri', '/activity')->exists()){
            $admin_menu = new Menu();
            $admin_menu->parent_id = 18;
            $admin_menu->order =  24;
            $admin_menu->title = '活动';
            $admin_menu->uri = '/activity';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

        if(!Schema::hasColumn('wx_icons', 'img')){
            Schema::table('wx_icons', function (Blueprint $table) {
                $table->string('img')->nullable()->after('icon')->comment('图片');
            });
        }

        if(!Schema::hasColumn('wx_icons', 'unicode16')){
            Schema::table('wx_icons', function (Blueprint $table) {
                $table->string('unicode16')->nullable()->after('icon')->comment('图片');
            });
        }

        if(!Schema::hasColumn('wx_icons', 'is_admin')){
            Schema::table('wx_icons', function (Blueprint $table) {
                $table->tinyInteger('is_admin')->default(0)->after('target_id')->comment('仅管理可见');
            });
        }

        if(!Schema::hasTable('wx_pages')){
            Schema::create('wx_pages', function (Blueprint $table) {
                $table->id();
                $table->string('title')->comment('页面标题');
                $table->string('right')->nullable()->comment('右上角图标');
                $table->tinyInteger('type')->comment('模板类型');
                $table->longText('config')->nullable()->comment('页面配置');
                $table->tinyInteger('status')->comment('状态');
                $table->softDeletes();
                $table->timestamps();
            });
        }

        if(!Menu::where('uri', '/pages')->exists()){
            $admin_menu = new Menu();
            $admin_menu->icon = 'fa-coffee';
            $admin_menu->parent_id = 0;
            $admin_menu->order =  45;
            $admin_menu->title = '页面模板';
            $admin_menu->uri = '/pages';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }

        if(!Menu::where('uri', '/settings/taoke')->exists()){
            $admin_menu = new Menu();
            $admin_menu->parent_id =60;
            $admin_menu->order = 7;
            $admin_menu->title = '淘客';
            $admin_menu->uri = '/settings/taoke';
            $admin_menu->extension = '';
            $admin_menu->show = 1;
            $admin_menu->save();
        }


        if(!Schema::hasColumn('wx_shop_goods', 'dtk_id')){
            Schema::table('wx_shop_goods', function (Blueprint $table) {
                $table->bigInteger('dtk_id')->nullable()->after('id')->comment('大淘客商品id');
                $table->unique('dtk_id', 'index_2');
            });
        }

        if(!Schema::hasColumn('wx_shop_goods', 'tk_platform_id')){
            Schema::table('wx_shop_goods', function (Blueprint $table) {
                $table->string('tk_platform_id')->nullable()->after('id')->comment('售卖电商平台id');
                $table->unique('tk_platform_id', 'index_3');
            });
        }

        Menu::where('id', 2)->update(['order'=> 999]);

        if(!Schema::hasTable('jobs')) {
            Schema::create('jobs', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->string('queue')->index();
                $table->longText('payload');
                $table->unsignedTinyInteger('attempts');
                $table->unsignedInteger('reserved_at')->nullable();
                $table->unsignedInteger('available_at');
                $table->unsignedInteger('created_at');
            });
        }
    }

    private function _v1_0_10(){
        if(!Schema::hasColumn('wx_tags', 'user_id')){
            Schema::table('wx_tags', function (Blueprint $table) {
                $table->bigInteger('user_id')->nullable()->after('id')->comment('用户id');
                $table->unique('tags_name', 'index_0');
                $table->index('user_id', 'index_1');
            });
        }

        if(!Schema::hasColumn('wx_attachment', 'user_id')){
            Schema::table('wx_attachment', function (Blueprint $table) {
                $table->bigInteger('user_id')->default(0)->after('id')->comment('用户id');
                $table->unique(['domain', 'path'], 'index_0');
                $table->index('user_id', 'index_1');
            });
        }

    }
}
